<?php
namespace app\index\controller;

use app\common\controller\HomeBase;
use app\common\model\Wacategory as WacategoryModel;
use app\common\model\Wenan as WenanModel;

class TitleList extends HomeBase
{
    protected $wacategory_model;
    protected $wenan_model;

    protected function _initialize(){
        parent::_initialize();
        $this->wacategory_model = new WacategoryModel;
        $this->wenan_model = new WenanModel;
        $category = $this->wacategory_model->where('pid',0)->select();
        $this->assign('category',$category);
    }
    
    public function title_list($id = '' , $type = 0 ,$page = 1){
        if(!empty($id)){
            $this->wacategory_model->where('id',$id)->setInc('click');
        }else{
            $id = 1;
        }
        
        // $article_list = $this->wenan_model->query("SELECT * FROM `think_wenan` WHERE `type` = {$type} AND  `wid` IN (SELECT id FROM think_wacategory WHERE pid = {$id}) ORDER BY `id` DESC")->paginate(2,false,['page' => $page]);
        $ids = $this->wacategory_model->where('pid',$id)->column('id');
        $article_list = $this->wenan_model->where('type',$type)->whereIn('wid',$ids)->order('id DESC')->paginate(16,false,['page' => $page]);
        $this->assign('article_list',$article_list);
        $this->assign('type',$type);
        $this->assign('id',$id);
        $this->assign('page',$page);
        return $this->fetch();
    }
}